package kt03

fun study01() = { name: String, age: Int ->
    true
    name
    age
    "我的姓名 是$name 我的年龄是$age"
}

fun study02() = { lambdaAction: (Int, Int) -> String, studyInfo: String ->
    false
    '男'
    val lambdaAction = lambdaAction(10, 10)
    println("最后我组装的值是$lambdaAction + $studyInfo")

}

fun study04() = { str: String, num: Int, lambda1: (String) -> Unit, lambda2: (Int) -> Unit ->

    lambda1(str)
    lambda2(num)
}

fun <T1, T2, R1, R2> study05() = { str: T1, num: T2, lambda: (T1) -> R1, lambda2: (T2) -> R2 ->
    println("调用第一个lambda:${lambda(str)} ${if (lambda(str) is Int) "变换后为Int" else "不是Int"}")
    println("调用第二个lambda:${lambda2(num)}")
}


fun main() {
    println(study01()("张三", 18))
    study02()({ num1, num2 ->
        "两数相加的结果 :${num1 + num2}"
    }, "张三")

    study04()("张三", 88, {
        println("第一个参数是$it")
    }) {
        println("第二个参数是$it")
    }
    println()
    study05<String, Int, Int, String>()("王五", 99, {
        // 变换操作：把String变成Int
        "值Ok: $it".length
    }) {
        // 变换操作：把Int变成String
        "第二个lambda是:$it"
    }
    show {
        println("AAAA")
    }
    repeat(10) {
        println("下标是：$it")
    }
    val r = "123".takeIf {
        it
        false
//        true
    }
    println(r)

    listOf("张三", "李四", "王五").zip(listOf(20, 21, 22)).toMap().map {
        println("name${it.key} value ${it.value}")
    }
}

// 宏替换 文本替换  inline 会做优化，不需要你开辟对象空间
inline fun show(lambda: () -> Unit) = lambda()